package com.house365.core.view;

import android.content.Context;
import android.content.res.TypedArray;
import android.util.AttributeSet;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.house365.core.R;

public class HeadNavigateView extends LinearLayout{
	private Button btn_left;
	private Button btn_right;
	private TextView tv_center;
	private String strBtnLeft;
	private String strBtnRight;
	private String strTitle;
	private int left_drawable;
	private int right_drawable;
	private int bg_drawable;
	private int btn_color;
	private int title_color;
	private float title_textsize;
	private float btn_textsize;
	public HeadNavigateView(Context context) {
		super(context);
	}
	public HeadNavigateView(Context context, AttributeSet attrs) {
		super(context, attrs);
		initAttributes(context,attrs);
		initContent(context);
	}

	private void initAttributes(Context context,AttributeSet attributeSet) {
		if (null != attributeSet) {
			TypedArray styledAttrs = context.obtainStyledAttributes(attributeSet,
					R.styleable.HeadNavigateView);
			CharSequence t1 = styledAttrs.getText(R.styleable.HeadNavigateView_btn_leftText);
			CharSequence t2 = styledAttrs.getText(R.styleable.HeadNavigateView_btn_rightText);
			CharSequence t3 = styledAttrs.getText(R.styleable.HeadNavigateView_tv_title);
			left_drawable = styledAttrs.getResourceId(R.styleable.HeadNavigateView_left_drawable, 0);
			right_drawable = styledAttrs.getResourceId(R.styleable.HeadNavigateView_right_drawable, 0);
			bg_drawable = styledAttrs.getResourceId(R.styleable.HeadNavigateView_bg_drawable, 0);
			btn_color = styledAttrs.getColor(R.styleable.HeadNavigateView_btn_color, 0);
			title_color = styledAttrs.getColor(R.styleable.HeadNavigateView_title_color, 0);
			title_textsize = styledAttrs.getDimension(
					R.styleable.HeadNavigateView_title_textsize, 20);
			btn_textsize= styledAttrs.getDimension(
					R.styleable.HeadNavigateView_btn_textsize,16);
			styledAttrs.recycle();
			if (null != t1) {
				strBtnLeft = t1.toString();
			}
			if (null != t2) {
				strBtnRight = t2.toString();
			}
			if (null != t3) {
				strTitle = t3.toString();
			}
			if(title_color==0){
				title_color = context.getResources().getColor(R.color.white);
			}
			if(btn_color==0){
				btn_color = context.getResources().getColor(R.color.white);
			}
		}

	}

	private void initContent(Context context) {
		setGravity(Gravity.CENTER_VERTICAL);
		LayoutInflater.from(context).inflate(R.layout.headnavigate, this);
	 
		btn_left = (Button) findViewById(R.id.btn_left);
		btn_right = (Button) findViewById(R.id.btn_right);
		tv_center =(TextView) findViewById(R.id.tv_center);
		
		if (left_drawable != 0) {
			btn_left.setBackgroundResource(left_drawable);
			btn_left.setVisibility(View.VISIBLE);
		}
		if (right_drawable != 0) {
			btn_right.setBackgroundResource(right_drawable);
			btn_right.setVisibility(View.VISIBLE);
		}
		if (null != strBtnLeft) {
			btn_left.setTextColor(btn_color);
			btn_left.setText(strBtnLeft);
			if(btn_textsize>0){
				btn_left.setTextSize(btn_textsize);
			}
		}
		if (null != strBtnRight) {
			btn_right.setTextColor(btn_color);
			btn_right.setText(strBtnRight);
			if(btn_textsize>0){
				btn_right.setTextSize(btn_textsize);
			}
		}
		if (null != strTitle) {
			tv_center.setText(strTitle);
			tv_center.setTextColor(title_color);
			tv_center.setVisibility(View.VISIBLE);
			if(title_textsize>0){
				tv_center.setTextSize(title_textsize);
			}
		}
	}
	public Button getBtn_left() {
		return btn_left;
	}
	public Button getBtn_right() {
		return btn_right;
	}
	public TextView getTv_center() {
		return tv_center;
	}
	public String getStrBtnLeft() {
		return strBtnLeft;
	}
	public String getStrBtnRight() {
		return strBtnRight;
	}
	public String getStrTitle() {
		return strTitle;
	}
	public int getLeft_drawable() {
		return left_drawable;
	}
	public int getRight_drawable() {
		return right_drawable;
	}
	public int getBg_drawable() {
		return bg_drawable;
	}
	public int getBtn_color() {
		return btn_color;
	}
	public int getTitle_color() {
		return title_color;
	}
	public float getTitle_textsize() {
		return title_textsize;
	}
	public float getBtn_textsize() {
		return btn_textsize;
	}
	public void setBtn_left(Button btn_left) {
		this.btn_left = btn_left;
	}
	public void setBtn_right(Button btn_right) {
		this.btn_right = btn_right;
	}
	public void setTv_center(TextView tv_center) {
		this.tv_center = tv_center;
	}
	public void setStrBtnLeft(String strBtnLeft) {
		this.strBtnLeft = strBtnLeft;
	}
	public void setStrBtnRight(String strBtnRight) {
		this.strBtnRight = strBtnRight;
	}
	public void setStrTitle(String strTitle) {
		this.strTitle = strTitle;
	}
	public void setLeft_drawable(int left_drawable) {
		this.left_drawable = left_drawable;
	}
	public void setRight_drawable(int right_drawable) {
		this.right_drawable = right_drawable;
	}
	public void setBg_drawable(int bg_drawable) {
		this.bg_drawable = bg_drawable;
	}
	public void setBtn_color(int btn_color) {
		this.btn_color = btn_color;
	}
	public void setTitle_color(int title_color) {
		this.title_color = title_color;
	}
	public void setTitle_textsize(float title_textsize) {
		this.title_textsize = title_textsize;
	}
	public void setBtn_textsize(float btn_textsize) {
		this.btn_textsize = btn_textsize;
	}
	
	public void setTvTitleText(CharSequence text){
		getTv_center().setText(text);
		getTv_center().setVisibility(View.VISIBLE);
		getTv_center().setTextColor(title_color);
		getTv_center().setTextSize(title_textsize);
	}
	public void setTvTitleText(int textId){
		getTv_center().setText(textId);
		getTv_center().setVisibility(View.VISIBLE);
		getTv_center().setTextColor(title_color);
		getTv_center().setTextSize(title_textsize);
	}
	
}
